#!/usr/bin/env python

def main(input):
    from sklearn.metrics import classification_report
    from sklearn.datasets import make_classification
    from sklearn.externals import joblib
    # import pickle
    from collections import OrderedDict
    import numpy as np
    import pandas as pd
    from rf.mlutil import read, write, data_prep, test_prep,
        xy_split, format_rf_test_results
    from rf.const import mode, class_col, filt
    # import rf.const as const

    if isinstance(input, pd.DataFrame):
        df = input
    else:
        df = read(input)
   
    if df.empty:
        return 'EMPTY TEST DATA'
        
    dat_fill_test = joblib.load('dat_fill_class.pkl')
    les = joblib.load('les.pkl')
    
    # test = test_prep(df, dat_fill_class, les, mode=mode,
        # class_col=0, filter=.5)
    X_test = test_prep(df, dat_fill_test, les, filt=filt)
    # X, y = xy_split(X_test)
    estimator_best = joblib.load('grid_search_best.pkl')
    # rfc = estimator_best.get_params()['estimator']
    pre_prob = format_rf_test_results(estimator_best, X_test)
    return pre_prob


if __name__ == '__main__':
    import argparse
    ap= argparse.ArgumentParser(description='rf test')
    ap.add_argument('file', help='input file')
    # ap.add_argument('sub', nargs='?', help='sub')
    ap.add_argument('-p', '--prefix', help='out prefix', default='1')
    # ap.add_argument('-r', '--rename', help='False default', action="store_true")
    args= ap.parse_args()
    main(args.file)
